package com.happy.zebra.admin.service.impl;

import com.happy.zebra.admin.mapper.AllocateMapper;
import com.happy.zebra.admin.service.AllocateService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@AllArgsConstructor
public class AllocateServiceImpl implements AllocateService {
    private final AllocateMapper allocateMapper;

    @Override
    public int updateStock(Integer goodsId, Integer optId, Integer orgId, Integer number, Integer duration){
        if(allocateMapper.countStockRow(goodsId, optId, orgId) > 0){
            Integer id = allocateMapper.countStockId(goodsId, optId, orgId);
            return allocateMapper.saveOrUpdateStock(id, goodsId, number, optId, orgId);
        }else{
            return allocateMapper.saveOrUpdateStock(null, goodsId, number, optId, orgId);
        }
    }
}
